import { getScore } from "@/static/js/pointsMall.js";
import { getUserInfo } from "@/static/js/my.js";
export default {
  data() {
    return {
      userInfo: {}, //用户信息
      pageShow: false,
      current: 0,
      tabList: [
        {
          id: 0,
          name: "全部",
        },
        {
          id: 1,
          name: "获取",
        },
        {
          id: 2,
          name: "兑换",
        },
        {
          id: 3,
          name: "失效",
        },
      ],
      page: 1,
      noMore: false,
      detailList: [],
      isRefreshing: false,
    };
  },
  onShow() {
    this.getUserInfo();
    this.page = 1;
    this.detailList = [];
    this.getDetail();
  },
  onLoad(e) {
    this.current = e.index ? e.index : 0;
  },
  methods: {
    //获取用户信息
    getUserInfo() {
      getUserInfo().then((res) => {
        this.userInfo = res.data;
        this.pageShow = true;
      });
    },

    //选项点击事件
    tabClick(val) {
      this.current = val.index;
      this.page = 1;
      this.detailList = [];
      this.getDetail();
    },

    //去规则页面
    goRules() {
      uni.navigateTo({
        url: "/pointsMall/pointsRules/index",
      });
    },

    //去充值页面
    goRecharge() {
      uni.navigateTo({
        url: "/pointsMall/recharge/index",
      });
    },

    //请求积分明细
    getDetail() {
      getScore({
        status: this.current,
        page: this.page,
        limit: 20,
      }).then((res) => {
        if (res.code == 1) {
          this.detailList = this.detailList.concat(res.data);
          this.noMore = res.data.length < 20 ? false : true;
          this.isRefreshing = false;
        } else {
          this.$tools.msg(res.msg);
        }
      });
    },

    // 下拉刷新
    refresherrefresh() {
      this.isRefreshing = true;
      this.page = 1;
      this.detailList = [];
      this.getDetail();
    },

    //上拉加载更多
    loadMore() {
      if (this.noMore) {
        this.page++;
        this.getDetail();
      }
    },
  },
};